package CollectionsFramework;


import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class MapTest {
    public static void main(String[] args) {
        Map<String, User> map = new HashMap<>();
        map.put("001", new User("张三", 18));
        map.put("002", new User("张三1", 18));
        map.put("003", new User("张三2", 18));
        map.put("004", new User("张三3", 18));
//1

//        Set<String> set = map.keySet();
//        Iterator<String> iterator = set.iterator();
//        while (iterator.hasNext()) {
//            String next = iterator.next();
//            System.out.println(next);
//            System.out.println(map.get(next));
//        }
        //2
//        Set<Map.Entry<String, User>> entries = map.entrySet();
//        Iterator<Map.Entry<String, User>> iterator1 = entries.iterator();
//        while (iterator1.hasNext()){
//            Map.Entry<String, User> next = iterator1.next();
//            System.out.println(next.getKey());
//            System.out.println(next.getValue());
//        }

        //3
        Set<Map.Entry<String, User>> entries1 = map.entrySet();
        for (Map.Entry<String, User> stringUserEntry : entries1) {
            System.out.println(stringUserEntry.getKey());
            System.out.println(stringUserEntry.getValue());
        }


    }
}
